# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=bluediving
pkgver=0.9
pkgrel=10
pkgdesc='A Bluetooth penetration testing suite.'
url='http://bluediving.sourceforge.net/'
groups=('blackarch' 'blackarch-bluetooth')
license=('GPL')
arch=('x86_64' 'aarch64')
depends=('bluez-utils' 'sox' 'obexftp' 'readline' 'expat' 'perl-xml-simple'
         'openobex' 'libxml2')
install='bluediving.install'
source=("http://downloads.sourceforge.net/sourceforge/bluediving/bluediving-$pkgver.tgz"
        'btftp.patch')
sha512sums=('8fc941cca2b4623eb5b9b6f34bb5ba4e7ea20861d537642627769a4245a9355e9640569e035478c55afd06e45bfd7fc7f26993a07ed207156e28962755e16e8e'
            'd922ad8c501ee65c2562271c958a33c17daa5899b186158b2428854818fd9d33e9aaac6b5b231fcb151b2fa002f1f66ccf2d82cac58516a32dd8a09605e404a4')

prepare() {
  cd "$pkgname-$pkgver"

  # Change the bluedivingNG.conf path to /etc.
  sed -i -e 's/bluedivingNG.conf/\/etc\/bluedivingNG.conf/g' bluedivingNG.pl

  # Change the paths of the compiled tools to /usr/bin/.
  sed -i -e 's/tools\//\/usr\/bin\//g' bluedivingNG.conf

  # Change the why-the-hell-am-I-having-such-a-long-name vcard path.
  sed -i -e '/vcards\/AAAA/ c\  <vcard>/usr/share/bluediving/AAA.vcf</vcard>' bluedivingNG.conf

  # Change the sounds paths.
  sed -i -e 's/sounds\//\/usr\/share\/bluediving\//g' bluedivingNG.conf

  # Fix libxml2 missing includes compilation error.
  sed -i -e 's/gcc/gcc `xml2-config --cflags`/g' tools/btftp_src/Makefile

  # Fix bss directory path.
  sed -i -e 's/bss-0.6/bss-0.8/g' tools/make_tools.sh

  cd tools/btftp_src
  patch < "$srcdir/btftp.patch"

  cp -f obex.c ../btobex_src
}

build() {
  cd "$pkgname-$pkgver/tools"

  sh make_tools.sh
}

package() {
  cd "$pkgname-$pkgver/tools"

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/etc"

  install -m 755 atshell attest btobex btftp greenplaque hcidump-crash hstest \
    l2cap-packet l2cap_headersize_overflow rfcomm_shell "$pkgdir/usr/bin"
  install -m 755 bdaddr "$pkgdir/usr/bin/bluediving-bdaddr"

  install -Dm 755 "$srcdir/bluediving-$pkgver/bluedivingNG.pl" \
    "$pkgdir/usr/bin/bluedivingNG.pl"
  install -Dm 644 "$srcdir/bluediving-$pkgver/bluedivingNG.conf" \
    "$pkgdir/etc/bluedivingNG.conf"
  install -Dm 644 "$srcdir/bluediving-$pkgver/vcards"/AAAAA*.vcf \
          "$pkgdir/usr/share/bluediving/AAA.vcf"

  install -Dm 644 "$srcdir/bluediving-$pkgver/sounds/explosion.wav" \
    "$pkgdir/usr/share/bluediving/explosion.wav"
  install -Dm 644 "$srcdir/bluediving-$pkgver/tools/carwhisperer-0.2/out.raw" \
    "$pkgdir/usr/share/bluediving/out.raw"
}

